import HTTP from '../utils/http';
import { API} from '../config/config';

const LOGIN = API.LOGIN;

class LoginService extends HTTP {
  /* 登录操作*/
  loginAction (userInfo) {
    return new Promise((resolve, reject) => {
      this.axiosPost({
        url: LOGIN.LOGIN_ACTION,
        data: userInfo,
        success(data) {
          resolve(data);
        },
        error(error) {
          alert('网络请求失败');
          // window.location.reload();
        }
      })
    });
  }

  /* 登录检查*/
  loginCheck () {
    return new Promise((resolve, reject) => {
      this.axiosGet({
        url: LOGIN.LOGIN_CHECK,
        success (data) {
          resolve(data);
          // console.log(data)
        },
        error(err) {
          alert('网络请求失败');
          window.location.reload();
        }
      })
    })
  }

  /* 退出登录*/
  logoutAction () {
    return new Promise((resolve, reject) => {
      this.axiosGet({
        url: LOGIN.LOGOUT_ACTION,
        success (data) {
          resolve(data);
          console.log(data)
        },
        error(err) {
          alert('网络请求失败');
          window.location.reload();
        }
      })
    })
  }
}

export default LoginService;
